Take-home_Ex01

Installing relevant R packages

pacman::p_load(arrow, classInt, lubridate, maptools, raster, sf, spatstat, sp, spNetwork, tidyverse, tmap, viridis)

Importing Aspatial Data (GrabPosisi)

grabdata <- read_parquet("D:/Kabeer2003/IS415 - GAA/Take-Home_Ex/Take-Home_Ex01/data/aspatial/GrabPosisi/part-00000.parquet")

Importing Spatial Data

map_sf <- st_read("D:/Kabeer2003/IS415 - GAA/Take-Home_Ex/Take-Home_Ex01/data/geospatial/MasterPlan2019SubzoneBoundaryNoSeaGEOJSON.geojson")
Reading layer `MasterPlan2019SubzoneBoundaryNoSeaGEOJSON' from data source 
  `D:\Kabeer2003\IS415 - GAA\Take-home_Ex\Take-home_Ex01\data\geospatial\MasterPlan2019SubzoneBoundaryNoSeaGEOJSON.geojson' 
  using driver `GeoJSON'
Simple feature collection with 332 features and 2 fields
Geometry type: MULTIPOLYGON
Dimension:     XY, XYZ
Bounding box:  xmin: 103.6057 ymin: 1.158699 xmax: 104.0885 ymax: 1.470775
z_range:       zmin: 0 zmax: 0
Geodetic CRS:  WGS 84
roads_sf <- st_read("D:/Kabeer2003/IS415 - GAA/Take-Home_Ex/Take-Home_Ex01/data/geospatial/gis_osm_railways_free_1.shp")
Reading layer `gis_osm_railways_free_1' from data source 
  `D:\Kabeer2003\IS415 - GAA\Take-home_Ex\Take-home_Ex01\data\geospatial\gis_osm_railways_free_1.shp' 
  using driver `ESRI Shapefile'
Simple feature collection with 5252 features and 7 fields
Geometry type: LINESTRING
Dimension:     XY
Bounding box:  xmin: 99.6614 ymin: 1.250935 xmax: 116.9729 ymax: 6.66987
Geodetic CRS:  WGS 84

Finding points of origin for each trip by setting the index to 1

start_points <- grabdata %>%
  group_by(trj_id) %>%
  slice(1) %>%
  dplyr::select(trj_id, latitude = rawlat, longitude = rawlng)

Similarly, finding points of destination for each trip by setting the index to (n)

end_points <- grabdata %>%
  group_by(trj_id) %>%
  slice(n()) %>%
  dplyr::select(trj_id, latitude = rawlat, longitude = rawlng)

Binding origin and destination points together for each trip

combined_points <- bind_rows(start_points, end_points)

Plotting the map

map_sf <- st_make_valid(map_sf)
roads_sf <- st_make_valid(roads_sf)

tmap_mode('view')
tmap mode set to interactive viewing
tm_shape(map_sf) +
  tm_borders() +
  tm_shape(roads_sf) +
  tm_lines()

Planned approach

Transform aspatial data (Follow In-class Exercise 2)

Plot on map using NKDE (Owin objects thingy) (Follow In-class Exercise 3)